using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class mgTrooper : soldier
{
    // Start is called before the first frame update
    public float bulletSpeed;
    public float destroyDelay;
    public float coolDownSet;
    public GameObject bulletPrefab;
    public float coolDownCout;
    void Start()
    {
        UdpPlatform=GameObject.Find("UdpServer");
    }

    // Update is called once per frame
    void FixedUpdate()
    {
        transform.rotation = transform.parent.rotation;
        transform.localPosition=localPos;
        coolDownCout+=Time.fixedDeltaTime;
        if(UdpPlatform.GetComponent<WebSocketDemo>().attackState[PlayerId] && coolDownCout>coolDownSet)
        {
            coolDownCout=0f;
            GameObject bullet = Instantiate(bulletPrefab, transform.position, transform.rotation);
            bullet.GetComponent<bulletAction>().PlayerId=PlayerId;

            // 获取子弹的Rigidbody2D组件
            Rigidbody2D rb = bullet.GetComponent<Rigidbody2D>();

            // 向Y轴方向添加力
            rb.AddForce(transform.up * bulletSpeed);

            Destroy(bullet, destroyDelay);
        }
        if(Health<=0)
        {
            if(PlayerId==UdpPlatform.GetComponent<WebSocketDemo>().PlayerId)
                Destroy(gameObject);
            else
                Health=1;
        }
    }
}
